<?php
//----------------------------------------------------------------------------------------------------------
   require_once('../config.inc.php');

   require_once($config['app_dir'] . '/includes/session.class.php');
   require_once($config['app_dir'] . '/classes/calcplot.class.php');
   //---------------------------------------------------------------------------------------------------
   // preparing data for graph
   //---------------------------------------------------------------------------------------------------
   $mode = 'month';


   if ( isset($_GET['mode']) && !empty($_GET['mode']) ) $mode = $_GET['mode'];

   $width = 630;
   $height = 300;
   //---------------------------------------------------------------------------------------------------
   switch( strtoupper($mode) ) {
      case 'D':
      case 'DAY':
         $data_name = 'CalculatorResultFcasts';
         $shift = false;
         break;
      case 'W':
      case 'WEEK':
         $data_name = 'CalculatorResultWeek';
         $shift = false;
         break;
      case 'M':
      case 'MONTH':
         $data_name = 'CalculatorResult';
         $shift = true;
         break;
   }//switch
   //------------------------------------------------------------------------------------------------------
   $Session = new objSession($config['app_id']);
   if( !$Session->isExists($data_name) || $Session->isEmpty($data_name)) exit;
   //------------------------------------------------------------------------------------------------------
   try {
      //---------------------------------------------------------------------------------------------------
      $CalcPlotView = new objCalcView($width, $height);
      //---------------------------------------------------------------------------------------------------
      if( !$CalcPlotView->is_cached ) {
         $CalcPlotView->HideLogo();
         $CalcPlotView->HideCopyright();

         $CalcPlotView->SetData($Session->Get($data_name));
         $CalcPlotView->ShiftLabels($shift);
         $CalcPlotView->Render();
      } //if not cached
      //---------------------------------------------------------------------------------------------------
   } catch (Exception $e) {
        echo 'Error: ',  $e->getMessage(), "\n";
   }
   //-------------------------------------------------------------------------------------------------------
?>
